import 'package:flutter/material.dart';

void main(List<String> args) {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      appBar: AppBar(title: const Text('button')),
      body: const MyAppBody(),
    ));
  }
}

class MyAppBody extends StatelessWidget {
  const MyAppBody({super.key});

  @override
  Widget build(BuildContext context) {
    return const Form();
  }
}

class Form extends StatefulWidget {
  const Form({super.key});
  @override
  State<Form> createState() => _FormState();
}

class _FormState extends State<Form> {
  List list = [
    {'label': '1323', 'value': 1},
    {'label': '232', 'value': 2}
  ];
  int radioValue = 1;
  dynamic selectValue;
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        selectDemo(list[0]['value']),
        radioItemDemo('男', 1),
        radioItemDemo('女', 0)
      ],
    );
  }

  // 下拉框
  Widget selectDemo(defaultValue) {
    return DropdownButtonFormField(
        value: defaultValue,
        items: list
            .map((e) => DropdownMenuItem(
                value: e['value'], child: Text('${e['label']}')))
            .toList(),
        onChanged: (val) {
          setState(() {
            selectValue = val;
          });
        });
  }

  // 单选框
  Widget radioItemDemo(title, value) {
    return RadioListTile(
        title: Text(title),
        toggleable: true,
        value: value,
        groupValue: radioValue,
        onChanged: (val) {
          setState(() {
            radioValue = val as int;
          });
        });
  }
  // 多选框
}
